﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace NativeWiFiLibrary
{
    public class NetworkDevice
    {
        public Guid DeviceGuid { get; set; }
        public String Description { get; set; }
        public NetworkState State { get; set; }

        /// <summary>
        /// Hide constructor
        /// </summary>
        private NetworkDevice() { }

        internal static NetworkDevice FromWlanApi(WlanApi.WlanInterfaceInfo original)
        {
            NetworkDevice device = new NetworkDevice();
            device.DeviceGuid = original.InterfaceGuid;
            device.Description = original.strInterfaceDescription;
            device.State = (NetworkState)original.isState;
            return device;
        }

        /// <summary>
        /// Scans for new networks.
        /// </summary>
        public void Scan()
        {
            using (WlanManager wlanManager = new WlanManager())
            {
                wlanManager.Scan(DeviceGuid);
            }
        }

        /// <summary>
        /// Returns a list of available networks.
        /// </summary>
        /// <returns></returns>
        public List<Network> GetAvailableNetworks()
        {
            using (WlanManager wlanManager = new WlanManager())
            {
                return wlanManager.GetAvailableNetworks(DeviceGuid);
            }
        }

        /// <summary>
        /// Disconnects from the currently active network.
        /// </summary>
        public void Disconnect()
        {
            using (WlanManager wlanManager = new WlanManager())
            {
                wlanManager.Disconnect(DeviceGuid);
            }
        }
    }
}